package com.zh.yqbj;

import java.util.*;


class ListNode {
    int val;
    ListNode next = null;

    public ListNode(int val) {
        this.val = val;
    }
}

public class Main {
    public static void main(String[] args) {
        ListNode node = new ListNode(1);
        node.next = new ListNode(2);
        node.next.next=new ListNode(3);
        node.next.next.next=new ListNode(2);
        node.next.next.next.next=new ListNode(1);
        System.out.println(isPail(node));
    }

    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * @param head ListNode类 the head
     * @return bool布尔型
     */
    public static boolean isPail(ListNode head) {
        // write code here
        ListNode p=head;
        int k=0;
        while (p!=null){
            k++;
            p=p.next;
        }
        int[] arr = new int[k];
        int i = 0;
        while (head != null) {
            arr[i] = head.val;
            i++;
            head = head.next;
        }
        for (int j = 0; j < arr.length; j++) {
            if(arr[j]!=arr[arr.length-j-1]){
                return false;
            }
        }
        return true;
    }
}
